package com.controller;

import com.model.DaoHang;
import com.model.MyEcharts;
import com.model.MyNode;
import com.model.MyUser;
import com.service.MyuserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Api("我的用户")
@RestController
@RequestMapping("/myuser")
public class MyuserController {

    @Autowired
    private MyuserService myuserService ;

//    //用户添加方法的对外接口
//    @RequestMapping(value = "/addUser" , method = RequestMethod.GET)
//    public int addUser (MyUser myUser){
//        System.out.println("进入用户添加方法") ;
//        return myuserService.addMyUser(myUser);
//     }

    //用户添加方法的对外接口
    @CrossOrigin
    @RequestMapping(value = "/addUser" , produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public int addUser (@RequestBody MyUser myUser){
        System.out.println("进入用户添加方法") ;
        return myuserService.addMyUser(myUser);
    }

    //用户修改方法的对外接口
    @CrossOrigin
    @RequestMapping(value = "/updateMyuser",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public int updateUser (@RequestBody MyUser myUser){
        System.out.println("进入用户修改方法，修改的主键为："+myUser.getUserid());
        return myuserService.updateMyUser(myUser);
    }

    //用户删除方法的对外接口
    @CrossOrigin
    @RequestMapping(value = "/deleteMyuser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public int deleteUser (int userid){
        System.out.println("进入用户删除方法，主键为："+userid);
        return myuserService.deleteMyUser(userid);
    }

    //用户查找方法的对外接口
    @CrossOrigin
    @RequestMapping(value = "/getUser",produces = "application/json;charset=utf-8",method = RequestMethod.GET)
    public MyUser getUser (int userid){
        System.out.println("进入根据主键id进行用户查找方法，主键为："+userid);
        return myuserService.getUser(userid);
    }

    //查询全部用户信息方法的对外接口
    @CrossOrigin //解决跨域问题
    @RequestMapping(value = "/getAll",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyUser> getAll(@RequestBody MyUser myUser){
        System.out.println("进入查询用户全部信息方法");
        System.out.println(myUser.getUsername()+"======"+myUser.getPwd());
        List<MyUser> myUserList=myuserService.getAllMyUsers(myUser);
        System.out.println(myUserList.size());
        return myUserList;
    }

//    //查询全部用户信息方法的对外接口
//    @CrossOrigin //解决跨域问题
//    @RequestMapping(value = "/getAll",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
//    public List<MyUser> getAll(@RequestBody MyUser myUser){
//        System.out.println("进入查询用户全部信息方法");
//        System.out.println(myUser.getUsername()+"======"+myUser.getPwd());
//        return myuserService.getAllMyUsers(myUser);
//    }

    @CrossOrigin
    @ApiOperation(value = "获取用户状态分析信息")
    @RequestMapping(value="/getEcharts",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<MyEcharts> getEcharts(@RequestBody MyUser myUser){
        System.out.println("进入 用户分析 方法");
        System.out.println(myUser.getUsername());
        List<MyEcharts> myEcharts=myuserService.EchartsMyUserStart(myUser);
        System.out.println(myEcharts.size());
        return myEcharts;
    }

    @CrossOrigin
    @ApiOperation(value = "根据用户主键获取操作模块的权限")
    @RequestMapping(value ="/getDaoHang",produces = "application/json;charset=utf-8",method = RequestMethod.PUT)
    public List<DaoHang> getDaoHang(@RequestBody MyUser myUser){
        System.out.println("进入 导航方法");
        //以下内容重点是模拟相关数据
        List<DaoHang> myDaoHangList =new ArrayList<>();

        //1.给第一个大模块下的子模块赋值虚拟数据
        List<MyNode> myNodeList1=new ArrayList<>();

        //2.给每一个子模块赋值
        MyNode myNode1=new MyNode();
        myNode1.setText("<span class='glyphicon glyphicon-user'>&nbsp;用户管理</span>");
        myNode1.setHref("userList.html");
        myNodeList1.add(myNode1);

        MyNode myNode2=new MyNode();
        myNode2.setText("信息统计");
        myNode2.setHref("serEcharts.html");
        myNodeList1.add(myNode2);

        //3.给第一个模块赋值
        DaoHang myDao=new DaoHang();
        myDao.setText("系统管理");
        myDao.setNodes(myNodeList1);

        //4.将所有大模块的属性放到集合当中
        myDaoHangList.add(myDao);

        return  myDaoHangList;
    }

}
